#include "man.h"
#include "coid/comm/token.h"

static token _class_id = "m";
static token _class_name = "man";

const token& man::class_id() const { return _class_id; }
const token& man::class_name() const { return _class_name; }

void man::dispatch( const uchar* pc, const uchar* pe )
{
	while(pc<pe) {
		uchar cmd = *pc++;
		if( cmd >= 0 && cmd < 8 )
		{
			cmd -= 0;
						((man*)this)->change_direction( cmd );
		}
		else if( cmd >= 8 && cmd < 12 )
		{
			cmd -= 8;
						((man*)this)->action( cmd );
		}
		else if( cmd == 12 )
		{
			uint32 a0 = *(uint32*)pc;		pc += sizeof(a0);
			uint32 a1 = *(uint32*)pc;		pc += sizeof(a1);
			token a2((const char*)pc+1,*pc);		pc += 1+*pc;
			((man*)this)->set_colors( a0, a1, a2 );
		}
		else if( cmd == 13 )
		{
			((man*)this)->disconnect( );
		}
		else DASSERT(0); //command id out-of-range
	}
}
